package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类管理
 */
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //--1--分页
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("分类分页查询，参数为：{}", categoryPageQueryDTO);
        PageResult result=categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(result);
    }


    //--2---新增
    @PostMapping()
    @ApiOperation("分类添加")
    public Result save(@RequestBody CategoryDTO categoryDTO) {
        log.info("分类添加，参数为：{}", categoryDTO);
        categoryService.saveOne(categoryDTO);
        return Result.success();
    }

    //--3---修改
    @PutMapping()
    @ApiOperation("分类修改")
    public Result update(@RequestBody CategoryDTO categoryDTO) {
        log.info("分类修改，参数为：{}", categoryDTO);
        categoryService.updateDTO(categoryDTO);
        return Result.success();
    }
    //--4---启用禁用
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result startOrStop(@PathVariable Integer status,Long id) {
        log.info("启用禁用分类:status={},  id={}", status,id);
        categoryService.startOrStop(status,id);
        return Result.success("修改成功");
    }
    //--5---id删除
    @DeleteMapping()
    @ApiOperation("根据id删除")
    public Result deleteById(Long id) {
        log.info("根据id删除，参数为：{}", id);
        categoryService.deleteById(id);
        return Result.success();
    }

    //--6--根据类型查询分类
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result selectByType(Integer type) {
        log.info("根据类型查询分类，参数为：{}", type);
        List<Category> categoryList=categoryService.selectByType(type);
        return Result.success(categoryList);
    }
}
